import type { PageType } from '../../../../lib/page_handler/type'
import type { ModulePlatformConfig } from '../../types'
import { BaiduPageType } from '../../../../lib/page_handler/platform/baidu/types.ts'
import { GreasyForkPageType } from '../../../../lib/page_handler/platform/greasyfork/types'
import { ZhiHuQuestionPageType } from '../../../../lib/page_handler/platform/zhi_hu_question/types'
import { SUPPORTED_PLATFORMS } from '../../../../types/constants'
import { EffectType, SYMBOLS } from '../../../../types/interfaces'
import { AppModule } from '../../types'

export function getGreasyForkModules(pageType: PageType): ModulePlatformConfig {
  return {
    [AppModule.GreasyForkScriptInstalls.id]: {
      meta: {
        name: '安装分级',
        description: '按安装量区间自动划分等级，用颜色和图标直观标识脚本热度',
        category: 'appearance',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.UI.NUM_OF_ITEMS}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本列表页和用户页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_LIST,
              GreasyForkPageType.USER_PROFILE,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkScriptValuation.id]: {
      meta: {
        name: '价值印记',
        description: '通过评分与标签，展示脚本质量等级；被需要的脚本才是最好的脚本，评分仅作参考',
        category: 'dataPresentation',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.USER.ADMIN}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本列表页和用户页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_LIST,
              GreasyForkPageType.USER_PROFILE,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkScriptNavigator.id]: {
      meta: {
        name: '脚本速览',
        description: '支持脚本搜索、排序、筛选与快速跳转，提升脚本发现效率（固定于页面顶部）',
        category: 'dataPresentation',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.OTHERS.VIEWED}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本列表页和用户页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_LIST,
              GreasyForkPageType.USER_PROFILE,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkFeedbackGroup.id]: {
      meta: {
        name: '时间轴',
        description: '按年月自动分组用户反馈，形成可视化时间轴，提升浏览效率',
        category: 'dataPresentation',
        icon: `${SYMBOLS.DOCUMENTS.NEWSPAPER}${SYMBOLS.TIME.CALENDAR}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本反馈页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_FEEDBACK,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkTimeHelper.id]: {
      meta: {
        name: '显示精确时间',
        description: '在原有时间显示后补充完整日期时间 (YYYY/MM/DD HH:MM:SS)',
        category: 'dataPresentation',
        icon: `${SYMBOLS.DOCUMENTS.NEWSPAPER}${SYMBOLS.TIME.CLOCK}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本反馈页、讨论页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_FEEDBACK,
              GreasyForkPageType.SCRIPT_DISCUSSION,
              GreasyForkPageType.DISCUSSIONS,
              GreasyForkPageType.DISCUSSIONS_DETAIL,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkScriptMark.id]: {
      meta: {
        name: '脚本标记',
        description: '为脚本列表提供交互式标记功能，支持通过工具栏添加状态标识，并实时显示可视化标记样式',
        category: 'interaction',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.UI.TAG}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本列表页和用户页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_LIST,
              GreasyForkPageType.USER_PROFILE,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkFeedbackMark.id]: {
      meta: {
        name: '反馈分类',
        description: '为脚本反馈提供多维度分类标记功能，支持内容标签生成、状态标记及基于标签的智能筛选',
        category: 'interaction',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.UI.BOOKMARK}`,
        status: 'not-needed',
        defaultEnabled: true,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.GREASY_FORK]: {
          status: 'supported',
          // 支持脚本反馈页
          pageTypeValidator: () => {
            const supportPages = [
              GreasyForkPageType.SCRIPT_FEEDBACK,
            ]
            return supportPages.includes(pageType as GreasyForkPageType)
          },
        },
      },
    },
    [AppModule.GreasyForkSearchNavigator.id]: {
      meta: {
        name: '脚本搜索',
        description: '识别域名并一键跳转至油叉脚本搜索页（悬浮于页面右侧中部）',
        category: 'navigation',
        icon: `${SYMBOLS.DOCUMENTS.SCROLL}${SYMBOLS.UI.SEARCH}`,
        status: 'supported',
        defaultEnabled: false,
        effectType: EffectType.IMMEDIATE,
      },
      supportedPlatforms: {
        [SUPPORTED_PLATFORMS.BAI_DU]: {
          pageTypeValidator: () => {
            const notSupportPages = [
              BaiduPageType.Advanced,
              BaiduPageType.NotFound,
            ]
            return !notSupportPages.includes(pageType as BaiduPageType)
          },
        },
        [SUPPORTED_PLATFORMS.ZHI_HU_QUESTION]: {
          pageTypeValidator: () => {
            const supportPages = [
              ZhiHuQuestionPageType.Question,
              ZhiHuQuestionPageType.Answer,
            ]
            return supportPages.includes(pageType as ZhiHuQuestionPageType)
          },
        },
      },
    },
  }
}
